﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class AddQuanHuyen : System.Web.UI.UserControl
    {
        public string filePathNewsIamge;
        public int idnextnew;
        DataTable dt;
        ListItem lt;
        protected void Page_Load(object sender, EventArgs e)
        {
            Cate1.Items.Clear();
            dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTable("tbl_TinhThanhPho");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lt = new ListItem(dt.Rows[i]["TinhThanhPho_Ten"].ToString(), dt.Rows[i]["TinhThanhPho_ID"].ToString());
                Cate1.Items.Add(lt);
            }
        }

        protected void btnAddNews_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_QuanHuyen", "QuanHuyen_ID"));
            if (txtName.Text != "")
            {
                idnextnew = nextid + 1;
                int catid = Convert.ToInt32(Cate1.SelectedValue);
                string value = "" + idnextnew + "," + catid + ",N'" + txtName.Text + "'";
                List<string> values = new List<string>();
                values.Add(value);
                DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_QuanHuyen", "insertonerow", values, false);
                Response.Redirect("/Admin/Index.aspx?panel=1&sub=12");
            }
            else
            {
                Response.Write("<script>alert('Bạn vui lòng nhập tên quận huyện')</script>");
            }

        }
    }
}